package com.iflytek.iot.redis.sharding.core;

import com.iflytek.iot.redis.sharding.core.constants.RedisShardingConstants;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author ZuRun
 * @date 2020/2/27 23:12:04
 */
public class RedisShardingFactory<T> implements IRedisShardingFactory<T> {

    private IRedisClientPool<T> redisClientPool = RedisShardingManager.getInstance();

    @Override
    public List<T> getRedisClients(IRedisGroup group) {
        return redisClientPool.getRedisClients(group);
    }

    @Override
    public List<T> getRedisClients() {
        return getRedisClients(RedisShardingConstants.DEFAULT_REDIS_GROUP);
    }

    @Override
    public T getRedisClient(String key) {
        return redisClientPool.getRedisClient(key);
    }

    @Override
    public T getRedisClient(IRedisGroup group, String key) {
        return redisClientPool.getRedisClient(group, key);
    }

    @Override
    public void execute(String key, Consumer<T> resourceConsumer) {
        redisClientPool.execute(key, resourceConsumer);
    }

    @Override
    public void execute(IRedisGroup group, String key, Consumer<T> resourceConsumer) {
        redisClientPool.execute(group, key, resourceConsumer);

    }

    @Override
    public <R> R execute(String key, Function<T, R> function) {
        return redisClientPool.execute(key, function);
    }

    @Override
    public <R> R execute(IRedisGroup group, String key, Function<T, R> function) {
        return redisClientPool.execute(group, key, function);
    }


}
